Hệ thống xếp lịch học tín chỉ cho sinh viên CNTT trên PHP & MySQL
111.144 lượt xem;
- thumbnail.php
- project /
1 <?php
2 $currDir=dirname(__FILE__);
3 include("$currDir/defaultLang.php");
4 include("$currDir/language.php");
5 include("$currDir/lib.php");
6
7 handle_maintenance();
8
9 // image paths
10 $p=array(
11 );
12
13 if(!count($p)) exit;
14
15 // receive user input
16 $t = $_GET['t']; // table name
17 $f = $_GET['f']; // field name
18 $v = $_GET['v']; // thumbnail view type: 'tv' or 'dv'
19 $i = $_GET['i']; // original image file name
20
21 // validate input
22 if(!in_array($t, array_keys($p))) getImage();
23 if(!in_array($f, array_keys($p[$t]))) getImage();
24 if(!preg_match('/^[a-z0-9_-]+\.(gif|png|jpg|jpeg|jpe)$/i', $i, $m)) getImage();
25 if($v != 'tv' && $v != 'dv') getImage();
26 if($i == 'blank.gif') getImage();
27
28 $img=$p[$t][$f].$i;
29 $thumb=str_replace(".$m[1]ffffgggg", "_$v.$m[1]", $img.'ffffgggg');
30
31 // if thumbnail exists and the user is not admin, output it without rebuilding the thumbnail
32 if(getImage($thumb) && !getLoggedAdmin()) exit;
33
34 // otherwise, try to create the thumbnail and output it
35 if(!createThumbnail($img, getThumbnailSpecs($t, $f, $v))) getImage();
36 if(!getImage($thumb)) getImage();
37
38 function getImage($img = ''){
39 if(!$img){ // default image to return
40 $img = './photo.gif';
41 $exit = true;
42 }
43
44 /* force caching */
45 $last_modified = filemtime($img);
46 $last_modified_gmt = gmdate('D, d M Y H:i:s', $last_modified) . ' GMT';
47 $expires_gmt = gmdate('D, d M Y H:i:s', $last_modified + 864000) . ' GMT';
48 $headers = (function_exists('getallheaders') ? getallheaders() : $_SERVER);
49 if(isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == $last_modified)){
50 @header("Last-Modified: {$last_modified_gmt}", true, 304);
51 @header("Cache-Control: private, max-age=864000", true);
52 @header("Expires: {$expires_gmt}");
53 exit;
54 }
55
56 $thumbInfo = @getimagesize($img);
57 $fp = @fopen($img, 'rb');
58 if($thumbInfo && $fp){
59 $file_size = filesize($img);
60 @header("Last-Modified: {$last_modified_gmt}", true, 200);
61 @header("Pragma:");
62 @header("Cache-Control: private, max-age=864000", true);
63 @header("Content-type: {$thumbInfo['mime']}");
64 @header("Content-Length: {$file_size}");
65 @header("Expires: {$expires_gmt}");
66 ob_end_clean();
67 @fpassthru($fp);
68 if(!$exit) return true; else exit;
69 }
70
71 if(!$exit) return false; else exit;
72 }
2 $currDir=dirname(__FILE__);
3 include("$currDir/defaultLang.php");
4 include("$currDir/language.php");
5 include("$currDir/lib.php");
6
7 handle_maintenance();
8
9 // image paths
10 $p=array(
11 );
12
13 if(!count($p)) exit;
14
15 // receive user input
16 $t = $_GET['t']; // table name
17 $f = $_GET['f']; // field name
18 $v = $_GET['v']; // thumbnail view type: 'tv' or 'dv'
19 $i = $_GET['i']; // original image file name
20
21 // validate input
22 if(!in_array($t, array_keys($p))) getImage();
23 if(!in_array($f, array_keys($p[$t]))) getImage();
24 if(!preg_match('/^[a-z0-9_-]+\.(gif|png|jpg|jpeg|jpe)$/i', $i, $m)) getImage();
25 if($v != 'tv' && $v != 'dv') getImage();
26 if($i == 'blank.gif') getImage();
27
28 $img=$p[$t][$f].$i;
29 $thumb=str_replace(".$m[1]ffffgggg", "_$v.$m[1]", $img.'ffffgggg');
30
31 // if thumbnail exists and the user is not admin, output it without rebuilding the thumbnail
32 if(getImage($thumb) && !getLoggedAdmin()) exit;
33
34 // otherwise, try to create the thumbnail and output it
35 if(!createThumbnail($img, getThumbnailSpecs($t, $f, $v))) getImage();
36 if(!getImage($thumb)) getImage();
37
38 function getImage($img = ''){
39 if(!$img){ // default image to return
40 $img = './photo.gif';
41 $exit = true;
42 }
43
44 /* force caching */
45 $last_modified = filemtime($img);
46 $last_modified_gmt = gmdate('D, d M Y H:i:s', $last_modified) . ' GMT';
47 $expires_gmt = gmdate('D, d M Y H:i:s', $last_modified + 864000) . ' GMT';
48 $headers = (function_exists('getallheaders') ? getallheaders() : $_SERVER);
49 if(isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == $last_modified)){
50 @header("Last-Modified: {$last_modified_gmt}", true, 304);
51 @header("Cache-Control: private, max-age=864000", true);
52 @header("Expires: {$expires_gmt}");
53 exit;
54 }
55
56 $thumbInfo = @getimagesize($img);
57 $fp = @fopen($img, 'rb');
58 if($thumbInfo && $fp){
59 $file_size = filesize($img);
60 @header("Last-Modified: {$last_modified_gmt}", true, 200);
61 @header("Pragma:");
62 @header("Cache-Control: private, max-age=864000", true);
63 @header("Content-type: {$thumbInfo['mime']}");
64 @header("Content-Length: {$file_size}");
65 @header("Expires: {$expires_gmt}");
66 ob_end_clean();
67 @fpassthru($fp);
68 if(!$exit) return true; else exit;
69 }
70
71 if(!$exit) return false; else exit;
72 }